#include "Game.h"


MyGame::MyGame()
{
}
MyGame::~MyGame()
{
}
void MyGame::Game_Init(HINSTANCE instance)
{
	_cl=new COLOR();
	winform=new WinForm(instance);
	dxdevice=new DXDevice(winform->Get_HWND());
	sf=new Surface(dxdevice->Get_Device());
	
}
void MyGame::Game_Run()
{	
	MSG msg;
	int done=0;
	DWORD frame_start= GetTickCount();
	DWORD tick_per_frame=10000;	
	while(!done)
	{
		
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if(msg.message==WM_QUIT) done=1;
			if(msg.wParam==VK_LEFT) 
			{
				sf->Set_rect(-10,0,-10,0);
				dxdevice->Get_Device()->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,40,65,78),1.0f,0);
			}
			if(msg.wParam==VK_RIGHT) 
			{
					sf->Set_rect(10,0,10,0);
					dxdevice->Get_Device()->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,40,65,78),1.0f,0);
			}
			if(msg.wParam==VK_UP) 
			{
				sf->Set_rect(0,-10,0,-10);
				dxdevice->Get_Device()->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,40,65,78),1.0f,0);
			}
			if(msg.wParam==VK_DOWN) 
			{
				sf->Set_rect(0,10,0,10);
				dxdevice->Get_Device()->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,40,65,78),1.0f,0);
			}
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			
		}
		sf->Draw_rect(dxdevice->Get_Device());
		DWORD now= GetTickCount();
		if(now-frame_start>=tick_per_frame)
		{
			_cl->Ran_Color();
			frame_start=now;
			dxdevice->Get_Device()->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(_cl->get_a(),_cl->Get_r(),_cl->Get_g(),_cl->Get_b()),1.0f,0);
			dxdevice->Get_Device()->BeginScene();
			dxdevice->Get_Device()->EndScene();
			dxdevice->Get_Device()->Present(NULL,NULL,NULL,NULL);			
		}		
	}	
}
void MyGame::Game_End()
{
	if(dxdevice->Get_Device()!=NULL)
		dxdevice->Get_Device()->Release();
	if(dxdevice->Get_d3d()!=NULL)
		dxdevice->Get_d3d()->Release();
}